/* eslint-disable @typescript-eslint/no-unused-vars */
/* eslint-disable @typescript-eslint/no-explicit-any */

import { ipcMain } from 'electron'
import { setGlobalState } from './shared'

const events = new Map([
  ['mock', (app: any, _args: any[]) => {
    console.log('mock')
    console.log(_args)
    // console.log(app)
  }],
  ['send', (app: any, _args: any[]) => {
    console.log('send')
  }],
  ['open', (app: any, _args: any[]) => {
    console.log('open')
  }],
  ['close', (app: any, _args: any[]) => {
    console.log('close')
  }],
  ['save', (app: any, _args: any[]) => {
    console.log('save')
  }],
  ['remove', (app: any, _args: any[]) => {
    console.log('remove')
  }],
  ['quit', (app: any, _args: any[]) => {
    app.quit()
  }],
  ['login', (app: any, _args: any[]) => {
    if (_args.length) setGlobalState(_args.shift())
  }]
])

export default function createChannel (app: Electron.App): void {
  for (const [key, callback] of events) {
    ipcMain.on(key, (_event, ...args) => callback(app, args))
  }
}
